$(function(){
	$("#validity").val(validity);
	getContractList(recId);
});


//合同回填
function getContractList(recId){
	$.ajax({ 
	 	url: ctp + "/contractController/getWorkerContracts.shtml",
	    data: {recId:recId},
		type : 'POST',
		async:false, 
		dataType: "json",
		success : function(result) {
			var list=result.list;
			var html="";
			for (var i = 0; i < list.length; i++) {
				html += '<div class="smart-layer_carousel justone" id="' + list[i].rec_id + '">'
				+ '<img src="' + ctp + '/' + list[i].path + '" layui-src="' + ctp + '/' + list[i].path + '">'
				+ '<p><a onclick="delContractByid(\'' + list[i].rec_id
				+ '\');">删除</a>'
				+'</div>';
				
				/*<a onclick="downContract(\''
					+ list[i].path + '\',\'' + list[i].name
					+ '\');">下载</a>*/
		    };
		    $('#contractList').html(html);
		    layui.layer.photos({
		        photos: '#contractList',
		        anim: 0
		    });
		}
	});
}

function delContractByid(recId){
	jconfirm("del('"+recId+"')","确定要删除所选的文件吗？");
}

function del(recId){
	$.ajax({ 
	 	url: ctp + "/workerController/workerContractDel.shtml",
	    data: {recId:recId},
		type : 'POST',
		async:false, 
		//dataType: "json",
		success : function(result) {
			if(result==''){
				$('#'+recId).remove();
				jalert9("删除成功！");
			}else{
				jalert(msg);
			}
		}
	});
}

function downContract(path,fileName){
	location.href=ctp + "/pubController/downloadFile.shtml?path="+path+"&fileName="+fileName;
}


function uploadFile(){
	var files=document.getElementById("contract").files;
	var fileStr="";
	for(var i=0;i<files.length;i++){
		fileStr+=files[i].name+'|';
	}
	$('#file-name').html(fileStr);
}

function contractAdd() {
	if (!Validator.Validate(document.getElementById("form1"), 1)) {
		return;
	}
	//表单渲染
	$('#form1').submit(function() {
		var options = {
			url : ctp + "/contractController/contractSave.shtml",
			type : 'POST',
			success : function(result) {
				if(result=='1') {  
					jalert9("保存成功！");
					setTimeout(function(){
						parent.searchData();
						back();
					},WARN_TIME_OUT);
				}else if(result=='0') {     
					jalert("保存失败，请联系管理员！");   
				}
			}
		};
		$('#form1').ajaxSubmit(options);
		return false;
	});

	$('#form1').submit();
}


function selectWorker(){
	layui.layer.open({
		type: 2,
		area: ['1000px', '450px'],
		title: "选择工人",
		fixed: false,
		maxmin: false,
		content: ctp + "/contractController/selectWorkerPage.shtml"
	});
}

function addWorker(workerId,workerName,jobno){
	$('#name').val(workerName);
	$('#jobno').val(jobno);
	$('#owner').val(workerId);
}

function back(){
	window.parent.closeDialogWin();
}